package com.csair.seam.controller.pc;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.csair.seam.domain.model.entity.Equip;
import com.csair.seam.domain.model.enums.VisitsModule;
import com.csair.seam.domain.model.param.EquipParam;
import com.csair.seam.domain.service.IEquipService;
import com.csair.seam.infrastructure.log.LogOperation;
import com.csair.seam.infrastructure.log.VisitsLog;
import com.csair.seam.infrastructure.web.BaseController;
import com.csair.seam.infrastructure.web.BaseResponse;
import com.csair.seam.infrastructure.web.ResponseCode;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.net.URLDecoder;

@Api(tags = "设备服务接口")
@RestController
@RequestMapping("/pc/equip")
public class EquipController extends BaseController {

	@Autowired
    private IEquipService equipService;
    
    @ApiOperation(value = "我的设备（分页）", notes = "getEquipPage",httpMethod="POST")
    @PostMapping(value = "/page")
    @LogOperation(bizName = "查询我的设备")
//    @VisitsLog(module = VisitsModule.MY_EQUIP)
    @VisitsLog(module = VisitsModule.MY_EQUIP_QUERY)
    public BaseResponse<IPage<Equip>> getEquipPage(@ApiParam(value = "查询参数")EquipParam param){
        param.setUserCode(getAccount());
        return  buildSuccess(equipService.findEquipPage(param));
    }

    @ApiOperation(value = "设备详情", notes = "getEquipByCode",httpMethod="GET")
    @GetMapping(value = "/detail/{equipCode}")
    @LogOperation(bizName = "查询设备详情")
    public BaseResponse<Equip> getEquipByCode(@PathVariable @ApiParam(value="设备编码",required = true) String equipCode) {
        Equip equip = equipService.findEquipByCode(equipCode);
    	if(equip == null) {
    		return new BaseResponse<>(ResponseCode.PARAM_ERROR,"没有该设备",null);
    	}
//    	if(!getAccount().equals(equip.getUserCode())) {
//    		return new BaseResponse<>(ResponseCode.ERROR,"当前用户无权查看该设备",null);
//    	}
    	return buildSuccess(equip);
    }

}

